package com.darren.euc.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "euc_provinces")
public class Province implements Serializable {

	private static final long serialVersionUID = 2861478466077717714L;

	@Id
	@Column(name = "id")
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;

	@Column(name = "province_id")
	private String provinceId;
	
	@Column(name = "province_name")
	private String provinceName;

	@OneToMany(targetEntity = City.class, cascade = CascadeType.REMOVE, fetch = FetchType.EAGER)
	@JoinColumn(name = "province_id", referencedColumnName = "province_id")
	private List<City> cities;
	
	@Column(name = "enable", nullable = false, columnDefinition = "int default 1")
	private boolean enable = true;


	public Integer getId() {
		return id;
	}


	public void setId(Integer id) {
		this.id = id;
	}

	

	public String getProvinceId() {
		return provinceId;
	}


	public void setProvinceId(String provinceId) {
		this.provinceId = provinceId;
	}


	public String getProvinceName() {
		return provinceName;
	}


	public void setProvinceName(String provinceName) {
		this.provinceName = provinceName;
	}


	public List<City> getCities() {
		if(null != cities){
			for(int i = cities.size() -1; i >= 0; i--){
				City city = cities.get(i);
				if(!city.isEnable()){
					cities.remove(i);
				}
			}
		}
		return cities;
	}


	public void setCities(List<City> cities) {
		this.cities = cities;
	}


	public boolean isEnable() {
		return enable;
	}


	public void setEnable(boolean enable) {
		this.enable = enable;
	}  	
}
